﻿Public Class FormOperAdd
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim oper_u As String
    Public ty As String
    Public current_procedure_No As Integer
    Public current_procedure_Name As String
    Dim objGt As New clsGt
    Dim dt As DataTable
    Dim objGtProcedureDetails As New clsGtProcedureDetails
    Private Sub FormOperAdd_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = current_procedure_Name & Me.Text
        oper_u = GetIniFile("LOGIN", "user", "", g_szInitFileName)
        setData()
    End Sub

    Public Sub setData()
        dt = objGt.getGt(ty, "'0','1'")
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        If dt.Rows.Count = 1 Then
            txt_ID.Text = dt.Rows(0)("sys_id")
            txt_oper_type_name.Text = dt.Rows(0)("oper_type_name")
            txt_type_value.Text = dt.Rows(0)("type_value")
            txt_size.Text = dt.Rows(0)("size")
            txt_batch_no.Text = dt.Rows(0)("batch_no")
            txt_assist_marker.Text = dt.Rows(0)("assist_marker_outsource")
            txt_operable_num.Value = Integer.Parse(dt.Rows(0)("picking_num"))
        Else
            If dt.Rows.Count > 1 Then
                MsgBox("有超过1个生产批次未结束，请确保当前只有1个批次正在生产中")
            End If
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(oper_u) Then
            MsgBox("请切换用户进行登录！")
            Exit Sub
        End If
        If Integer.Parse(txt_num.Value) > 0 Then
            If Integer.Parse(txt_operable_num.Value) >= Integer.Parse(txt_num.Value) Then
                Dim en As New entity_gt_procedure_details
                en.procedure_No = current_procedure_No
                en.oper_num = Integer.Parse(txt_num.Value)
                en.oper = oper_u
                en.b_gt_sys_id = Integer.Parse(txt_ID.Text)
                en.validity = "1"
                Dim rtn As Integer = objGtProcedureDetails.save(en)
                If rtn <> -2 Then
                    MsgBox("入料成功")
                    If txt_oper_type_name.Text.Equals("法兰板") Then
                        If current_procedure_No = 2 Then
                            'todo 设定flb的plc
                            MsgBox("设定flb的plc")
                        End If
                    End If
                    Close()
                Else
                    MsgBox("入料失败")
                End If
            Else
                MsgBox("入料数量需≤可入料数量！")
            End If
        Else
            MsgBox("入料数量需>0")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

End Class

Public Class entity_gt_procedure_details
    Public procedure_No As String   ' 工序
    Public oper_num As Integer   ' 操作数
    Public oper As String   '操作员
    Public b_gt_sys_id As Integer  '关联ID
    Public validity As String '有效性
End Class